package com.lance.answer.question_export;

import com.alibaba.fastjson.JSONObject;
import com.lance.answer.dto.Item;
import com.lance.answer.dto.QuestionAnswer;
import com.lance.answer.gui.answer.Util;
import org.apache.commons.io.FileUtils;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author yixun
 * @version 2.0.0
 * @description  校验JSON文本答案是否符合要求
 * @date 2021-06-09 15:45
 * @since 2.0.0
 */
public class AnswerValid {

  public static void main(String[] args) throws IOException {
    //   String path = "/Users/guiliangzhou/IdeaProjects/answer-tool/src/main/resources/00747/00747-success.json";
    //  String path = "D:\\project\\answer-tool\\src\\main\\resources\\03129\\社会心理适应.answer";
    //  String path = "D:\\project\\answer-tool\\src\\main\\resources\\02480\\药物化学-answer.json";
    //   String path = "D:\\project\\answer-tool\\src\\main\\resources\\病理学与病理生理学\\病理学与病理生理学-answer.json";
    //  String path = "D:\\project\\answer-tool\\src\\main\\resources\\人体解剖生理学\\人体解剖生理学-answer.json";
    //    String path = "D:\\project\\answer-tool\\src\\main\\resources\\商务英语1\\商务英语1-answer.json";
    //    String path = "D:\\project\\answer-tool\\src\\main\\resources\\政治学原理\\政治学原理-answer.json";
    //   String path = "D:\\project\\answer-tool\\src\\main\\resources\\网络实用技术基础\\网络实用技术基础-answer.json";
    // String path = "D:\\project\\answer-tool\\src\\main\\resources\\宪法学\\宪法学-answer.json";
    //     String path = "D:\\project\\answer-tool\\src\\main\\resources\\人文社会科学基础\\人文社会科学基础-answer.json";
    //   String path = "D:\\project\\answer-tool\\src\\main\\resources\\经济数学基础12\\经济数学基础12-answer.json";
    String path = "D:\\project\\answer-tool\\src\\main\\resources\\人体生理学\\人体生理学-answer.json";
    File file = new File(path);
    String str = FileUtils.readFileToString(file,"utf-8");
    List<QuestionAnswer> questionAnswerList = JSONObject.parseArray(str,QuestionAnswer.class);
    System.out.println(questionAnswerList.size());
    for (QuestionAnswer questionAnswer:questionAnswerList) {
      List<String> answers = questionAnswer.getAnswers();
      List<Item> items = questionAnswer.getItems();
      Set<String> set = new HashSet<>();
      if (CollectionUtils.isEmpty(items)) {
        continue;
      }
      for (Item item:items) {
        set.add(Util.dealContent(item.getContent()));
      }
      for (String ans:answers) {
        if (!set.contains(ans)) {
          System.out.println(questionAnswer.getQuestionCode());
        }
      }
    }
  }
}
